
package components {
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;



public class OldButton extends JayButton {
    private static const DISABLED:String = "disable";
    private static const NORMAL:String = "normal";
    private static const HOVER:String = "hover";
    private static const CLICK:String = "click";

    private var _state:String = NORMAL;
    private var _label:TextField;
    private var _disabled:Boolean;

    public function OldButton(text:String="button") {
        gotoAndStop(_state);

        var format:TextFormat = new TextFormat();
        format.align = TextFormatAlign.CENTER;

        _label = new TextField();
        _label.setTextFormat(format);
        _label.selectable = false;
        _label.width = width;
        _label.height = height;
        _label.text = text;




        addEventListener(MouseEvent.MOUSE_OVER, onOver);
        addEventListener(MouseEvent.MOUSE_OUT, onOut);
        addEventListener(MouseEvent.MOUSE_DOWN, onPress);
        addEventListener(MouseEvent.MOUSE_UP, onUp);

        addChild(_label);

    }

    public function get disabled():Boolean
    {
        return _disabled;
    }
    public function set disabled(dis:Boolean):void
    {
        _disabled = dis;
        if (_disabled)
        {
            _state = DISABLED;
            gotoAndStop(DISABLED);
        }
        else
        {
            _state = NORMAL;
            gotoAndStop(NORMAL);
        }

    }

    public function setWidth(p_width:int):void
    {
        width = p_width;
        _label.width =width;
    }

    private function onUp(event:MouseEvent):void
    {
        if (_state!=DISABLED)
        {
            dispatchEvent(new MouseEvent(MouseEvent.CLICK));
            gotoAndStop(NORMAL);
        }
    }
    private function onOver(event:MouseEvent):void
    {
        if (_state!=DISABLED)
        {
            gotoAndStop(HOVER);
        }

    }
    private function onOut(event:MouseEvent):void
    {
        if (_state!=DISABLED)
        {
            gotoAndStop(NORMAL);
        }

    }
    private function onPress(event:MouseEvent):void
    {
        if (_state!=DISABLED)
        {
            gotoAndStop(CLICK);
        }
    }
}
}
